<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="fy.bean.*,java.util.*,java.io.*"%>
<%
    request.setCharacterEncoding("utf-8");	
    int id = Integer.parseInt(request.getParameter("id"));
    System.out.println("id :"+id);
    String lb = null;
    if((request.getParameter("category")!=null)){
     lb = request.getParameter("category");
    }else if(session.getAttribute("category")!=null){
     lb =session.getAttribute("category").toString();
    }else{
      response.sendRedirect("../backstage.jsp");
    }
    session.setAttribute("category", lb);
	PictureBean pictureBean = new PictureBean();
    pictureBean = pictureBean.findNewsById(id);
%>
<!DOCTYPE html>
<html>

<head>

<style type="text/css">
table {
	margin-top: 5px;
	width: 100%;
}

td {
	height: 35px;
}

.left {
	width: 12%;
	text-align: center;
	background-color: #e6f2fe;
}

.form {
	border-color: #acd0d0;
}

.pic {
	height: 200px;
	text-align: center;
}
</style>


<meta charset="UTF-8">
<title>Insert title here</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../webupload/bootstrap/css/bootstrap.min.css"
	rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css"
	href="../webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="../webupload/style.css">
<style type="text/css">
.update_input {
	margin-top: 5px;
	margin-bottom: 5px;
	width: 100%;
}
</style>
</head>

<body
	style="padding-left: 20px; padding-right: 20px; padding-bottom: 50px;">

	<div class="abroad">
		<div class="within">
			<div>
				<table class="form" border="1" cellpadding="5" cellspacing="0">
					<tbody>
						<tr>
							<td class="left">*分类：</td>
							<td class="right" style="padding-left: 3px;"><select
								id="category" name="channelId"
								value="<%=pictureBean.getCategory()%>"
								style="height: 30px; width: 40%;">
								<option value="dblb" class="sel-disabled">顶部轮播</option>
									<option value="tblb" class="sel-disabled">头部轮播</option>
								 <option value="lmtp" class="sel-disabled">栏目图片</option>
							</select></td>
							
							<td class="left">是否放在首页：</td>
							<td><select name="select2" id="homepage"
								style="margin-left: 3px; height: 30px">
									<option>--请选择--</option>
									 <% if(pictureBean.getHomepage()==1){
      %>
       <option value="1" selected="selected" >是</option>
      <%  
       }else{
      %>
       <option value="1" >是</option>
      <%  
       }
      %>
      <%
       if(pictureBean.getHomepage()==0){
      %>
       <option value="0" selected="selected" >否</option>
      <%  
       }else{
      %>
       <option value="0" >否</option>
      <%  
       }
      %>
							</select></td>

                        
						</tr>
						<tr>
       <td class="left">*标题：</td>
       <td class="right" style="padding-left: 3px;"><input type="text" id="title"
        value="<%=pictureBean.getTitle()%>"
        style="width: 99.5%; height: 30px; margin-left: 3px;">
        
       
 
						
						
						<td class="left">链接：</td>
							<td>
							<input type="" name="" id="link"
							value="<%=pictureBean.getLink()%>"
							 style="width: 40%; height: 30px; margin-left: 3px;">
							</td>
							</tr>
						
						
						
			
						<tr>
							<td class="left pic">原来图片：</td>
							<td class="pic"><img src="<%=pictureBean.getPicture()%>"
								style="margin: 5px; height: 200px"></td>
								</td>
							<td class="left">修改图片：</td>
							<td class="pic">
								<div class="uploader uploader1" style="margin: 5px;">
									<div class="wrapper">
										<div class="file-list"></div>
									</div>
									<div class="actions-area">
										<div class="actions">
											<div class="filePicker action">选择图片</div>
											<button class="uploadFile action upload-btn disabled">上传图片</button>
										</div>
									</div>
								</div>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div>
		<div style="margin-bottom: 20px">
			<input id="picture" value="<%=pictureBean.getPicture()%>"
				style="display: none;" />
			<div>
				<script>
   document.getElementById("category").value = "<%=pictureBean.getCategory()%>";
</script>
				<div style="text-align: center;">
					<button id="submit" class="update_button">递交</button>
				</div>
				<script type="text/javascript"
					src="../ueditor/third-party/jquery-1.10.2.js"></script>
				<!-- 配置文件 -->
				<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
				<!-- 编辑器源码文件 -->
				<script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
				<!-- 实例化编辑器 -->
				<script type="text/javascript">
				var editor = UE.getEditor('container');
				$("#submit").click(function () {
					var category = $("#category").val();
					var title = $("#title").val();
					var picture = $("#picture").val();
					var homepage = $("#homepage").val();
					var link = $("#link").val();
					var categoryname = $("#category").find("option:selected").text();
					$.ajax({
						cache: true,
						type: "post",
						url: "donews/updata.jsp",
						data: {
							category: category,
							title: title,
							picture: picture,
							homepage: homepage,
							link: link,
							categoryname:categoryname,
						    id:<%=id%>
					},
					async : false,
					error : function (request) {
						alert("Connection error");
					},
					success : function () {
						alert("success");
						window.location.href ="lbtp.jsp?category=<%=session.getAttribute("category")%>";
												}
											});
								});
			</script>
			<script src="../webupload/jquery.min.js"></script>
			<!-- Include all compiled plugins (below), or include individual files as needed -->
			<script src="../webupload/bootstrap/js/bootstrap.min.js"></script>
			<script src="../webupload/webuploader.js"></script>
			<script src="../webupload/webuploader.support.js"></script>
			<script>
				var w1 = new WebUploaderSupport({
					server : "../FileUploadServlet",
					paste : document.body,
					swf : '../webuploader/Uploader.swf' // swf文件所处路径
					,
					support : {
						uploader : ".uploader.uploader1", //上传区域容器选择器
						fileSize : 6, //文件总个数, -1时无限制

						uploadSuccess : function(file, data) {
							var $item = this.getItem(file), $state = $item
									.find('.state');
							$item.find('.progress').hide();
							if (data.status) { //上传成功时
								this.uploadSuccessCallbck($item, data); //用于标识为服务端文件
								if (!$state.hasClass('success')) {
									$state.attr("class", "state success");
									$state.text('上传成功');
									$("#myimg").attr("src", data.path);
									$("#picture").attr("value", data.path);
									$item.attr("data-server-file", "true");
									$item.attr("data-delete-url",
											data.delurl);
									alert(data.delurl);
								}
								$item.removeClass("retry");
							} else {
								if (!$state.hasClass('error')) {
									$state.attr("class", "state error");
									$state.text('上传失败');
								}
								$item.addClass("retry");
							}
						},

						deleteServerFile : function($item, url,
								deleteServerFileCallback) {
							var self = this;
							$.ajax({
								dataType : "json",
								type : "post",
								url : "../" + url,
								success : function(json) {
									deleteServerFileCallback(self, $item,
											json); //通过callback执行业务操作
									//文件操作完成后重新加载选择按钮样式
									self.loadChooseFileBtnStyle();
									$("#myimg").attr("src", "");
									$("#picture").attr("value", "");
								}
							});
						},
					}
				});
			</script>
		</div>
</body>

</html>